<?xml version="1.0" encoding="UTF-8"?>

<!--
    Document   : joinFeed-User.xsl
    Created on : June 12, 2013, 9:50 PM
    Author     : Khanh
    Description:
        Purpose of transformation follows.
-->

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
    <xsl:output method="xml" indent="yes" encoding="UTF-8"/>
    <xsl:param name="userXML"/>
    <xsl:variable name="user" select='document($userXML)'></xsl:variable>

    <!-- TODO customize transformation rules 
         syntax recommendation http://www.w3.org/TR/xslt 
    -->
    <xsl:template match="/">
        <feeds xmlns="http://xml.netbeans.org/schema/feed-user">
            <xsl:for-each select="//feed">
                <feed>
                    <feedId>
                        <xsl:value-of select="feedId" />
                    </feedId>
                    <url>
                        <xsl:value-of select="url" />
                    </url>
                    <title>
                        <xsl:value-of select="title" />
                    </title>
                    <decription>
                        <xsl:value-of select="decription" />
                    </decription>
                    <addedDate>
                        <xsl:value-of select="addedDate" />
                    </addedDate>
                    <userlist>
                        <xsl:for-each select="userlist/userId">
                            <xsl:variable name="currentId" select="."></xsl:variable>
                            <username>
                                <xsl:value-of select="$user/users/user[userId = $currentId]/username" />
                            </username>
                        </xsl:for-each>
                    </userlist>
                </feed>
            </xsl:for-each>
        </feeds>
    </xsl:template>

</xsl:stylesheet>
